<script setup lang="ts">
import { ref, watch } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import { compileScript } from "vue/compiler-sfc";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    ip: "",
    port: "",
    brand: "",
    note: "",
    moveheight: null,
    model: null,
    movelowheight: null,
    status: null,
    vehicletype: null,
    mapid: null,
    chargingpoint: null,
    stoppoint: null,
    sort: null
  }),
  agvModel: [],
  vehicletype: [],
  mapTypes: [],
  agvBrands: [],
  chargingSelect: [],
  stopSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const agvModel = ref(props.agvModel);
const vehicletype = ref(props.vehicletype);
const mapTypes = ref(props.mapTypes);
const chargingSelect = ref(props.chargingSelect);
const stopSelect = ref(props.stopSelect);
const { switchStyle } = usePublicHooks();

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="80px">
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="车辆名称" prop="name">
          <el-input v-model="newFormInline.name" clearable placeholder="请输入车辆名称" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="品牌" prop="brand">
          <el-select v-model="newFormInline.brand" placeholder="请选择品牌" style="width:100%">
            <el-option v-for="item in agvBrands" :key="item.Code" :label="item.Name" :value="item.Code" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="IP地址" prop="ip">
          <el-input v-model="newFormInline.ip" clearable placeholder="请输入IP地址" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="通讯端口" prop="port">
          <el-input v-model="newFormInline.port" clearable placeholder="请输入通讯端口" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="型号" prop="model">
          <el-select v-model="newFormInline.model" placeholder="请选择型号" style="width:100%">
            <el-option v-for="item in agvModel" :key="item.Code" :label="item.Name" :value="item.Code" />
          </el-select>
        </el-form-item>
      </re-col>
      <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="车型" prop="vehicletype">
          <el-select v-model="newFormInline.vehicletype" placeholder="请选择车型" style="width:100%">
            <el-option v-for="item in vehicletype" :key="item.Code" :label="item.Name" :value="item.Code" />
          </el-select>
        </el-form-item>
      </re-col> -->
      
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="行走高度" prop="moveheight">
          <el-input-number v-model="newFormInline.moveheight" controls-position="right" placeholder="请输入行走高度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="载货行走高度" prop="movelowheight" label-width="120px">
          <el-input-number v-model="newFormInline.movelowheight" controls-position="right" placeholder="请输入载货行走高度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="适用地图" prop="mapid">
          <el-select v-model="newFormInline.mapid" placeholder="请选择适用地图" style="width:100%">
            <el-option v-for="item in mapTypes" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="newFormInline.sort" controls-position="right" placeholder="请输入排序" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="状态" prop="status">
          <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0" active-text="启用"
            inactive-text="停用" :style="switchStyle" />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="充电点" prop="chargingpoint">
          <el-select v-model="newFormInline.chargingpoint" multiple placeholder="请选择充电点" style="width:100%">
            <el-option v-for="item in chargingSelect" :key="item.stationid" :label="item.stationname"
              :value="item.stationid" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="返航点" prop="stoppoint">
          <el-select v-model="newFormInline.stoppoint" multiple placeholder="请选择返航点" style="width:100%">
            <el-option v-for="item in stopSelect" :key="item.stationid" :label="item.stationname"
              :value="item.stationid" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="备注" prop="note">
          <el-input v-model="newFormInline.note" clearable placeholder="请输入备注" type="textarea" />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
  margin-right: 16px;
}
</style>
